import unittest
import ddt

from Base.BaseSetting import TestData_dir
from Business.ClassManagement_w import Stu_manage
import time
import datetime


@ddt.ddt
class Test_Stu_manage(unittest.TestCase):
    def setUp(self) -> None:
        self.t = Stu_manage()

    time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
    opening_time = time.split(' ')[0]
    dt = datetime.datetime.strptime(opening_time, "%Y-%m-%d")
    end_time = (dt + datetime.timedelta(days=2)).strftime("%Y-%m-%d")
    start_cls_time = (dt + datetime.timedelta(days=5)).strftime("%Y-%m-%d")


    @ddt.file_data(TestData_dir+'Stu_queryClass_w.json')
    def test_queryClass(self, **kwargs):
        """按条件查询把班级信息检测返回结果是否符合要求"""
        author = '吴小静 '
        module = '班务管理'
        res = self.t.queryClass(kwargs.get('pageSize'), kwargs.get('pageIndex'), kwargs.get('regionId'),
                                kwargs.get('openStatus'))
        for i in res.get('list'):
            actual = i.get('opening_status')
            self.assertEqual(actual, kwargs.get('expect'))


    @ddt.file_data(TestData_dir+'addClass_w.json')
    def test_addClass(self, **kwargs,):
        """检测新增班级信息是否正确"""
        author = '吴小静 '
        module = '班务管理'
        import time
        time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
        opening_time = time.split(' ')[0]
        dt = datetime.datetime.strptime(opening_time, "%Y-%m-%d")
        start_cls_time = (dt + datetime.timedelta(days=5)).strftime("%Y-%m-%d")
        actual = self.t.addClass(kwargs.get('class_no'),start_cls_time,kwargs.get('headmaster_id'))
        self.assertEqual(actual, kwargs.get('expect'))


    @ddt.file_data(TestData_dir+'queryLeave_w.json')
    def test_queryLeave(self, **kwargs):
        """按条件查询学生请假信息检测返回结果是否正确"""
        author = '吴小静 '
        module = '班务管理'
        res = self.t.queryLeave(kwargs.get('pageSize'), kwargs.get('pageIndex'), kwargs.get('leaveStatus'),
                                kwargs.get('regionId'))
        for i in res['list']:
            antual = i['leave_status']
            self.assertIn(antual, kwargs.get('expect'))



    @ddt.file_data(TestData_dir+"addLeave_w.json")
    def test_addLeave(self, **kwargs):
        """新增学员请假信息检测是否新增成功"""
        author = '吴小静 '
        module = '班务管理'
        import time
        time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
        opening_time = time.split(' ')[0]
        dt = datetime.datetime.strptime(opening_time, "%Y-%m-%d")
        end_time = (dt + datetime.timedelta(days=2)).strftime("%Y-%m-%d")
        antual = self.t.addLeave(kwargs.get('student_id'), opening_time,end_time,
                                 kwargs.get('days'), kwargs.get('leave_count'))
        self.assertEqual(antual, kwargs.get('expect'))




    @ddt.file_data(TestData_dir+'queryStuByInfo_w.json')
    def test_queryStuByInfo(self, **kwargs):
        """查询学生转班信息"""
        author = '吴小静 '
        module = '班务管理'
        res = self.t.queryStuByInfo(kwargs.get('pageSize'), kwargs.get('pageIndex'), kwargs.get('stuClass'),
                                    kwargs.get('regionId'))
        if res['list'] != []:
            for i in res['list']:
                antual = i['class_no']
                self.assertEqual(antual, kwargs.get('expect'))
        else:
            self.assertEqual(str(res['list']), kwargs.get('expect'))


if __name__ == '__main__':
    unittest.main()
